{% extends "rules/base.html" %}
{% block sidebar %}
    <div class="panel-heading">
        <h2 class="panel-title">{{ category.name|capfirst }}</h2>
    </div>
    <ul class="panel-body">
        <li>
            <span class="type">Filename:</span>
            <span>{{ category.filename }}</span>
        </li>
        <li>
            <span class="type">Created:</span>
            {{ category.created_date }}
        </li>
    </ul>
    <div class="panel-heading">
        <h2 class="panel-title">Action{% if perms.rules.ruleset_policy_edit %}s{% endif %}</h2>
    </div>
    <ul class="action panel-body">
        {% if perms.rules.ruleset_policy_edit %}
            <li>
                <a href="{% url 'disable_category' category.pk %}">Disable category</a>
            </li>
            <li>
                <a href="{% url 'enable_category' category.pk %}">Enable category</a>
            </li>
        {% endif %}
        {% if perms.rules.ruleset_policy_view %}
            <li>
                <a href="{% url 'transform_category' category.pk %}">Transform category</a>
            </li>
        {% endif %}
    </ul>
{% endblock sidebar %}
{% block content %}
    <ul class="nav nav-tabs" id="category-info">
        {% for rule in rules %}
            <li class="{% if forloop.first %}active{% endif %}">
                <a href="#version_{{ rule.version }}">
                    {% if rule.version < 39 %}< v39 {% else %}v{{ rule.version }}{% endif %}
                </a>
            </li>
        {% endfor %}
    </ul>
    <div class="tab-content">
        {% for rule in rules %}
            <div class="tab-pane fade {% if forloop.first %}active{% endif %} in" id="version_{{ rule.version }}">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-6">
                            <h2 class="title">Rules ({{ rule.active.rows|length }})</h2>
                            {% load render_table from django_tables2 %}
                            {% render_table rule.active %}
                        </div>
                        <div class="col-md-6">
                            <div class="container-fluid">
                                <div class="row">
                                    <h2 class="title">Status in rulesets</h2>
                                    {% load render_table from django_tables2 %}
                                    {% render_table rule.rulesets %}
                                </div>
                                <h2 class="title">Commented rules ({{ rule.commented_rules.rows|length }})</h2>
                                <div class="row">{% render_table rule.commented_rules %}</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        {% endfor %}
    </div>
    <script>
$(document).ready(function(){
    var activeTab = localStorage.getItem('categoryactiveTab');
    if(activeTab){
        $('#category-info li').siblings().removeClass('active');
        $('#category-info a[href="' + activeTab + '"]').tab('show');
        $('#category-info a[href="' + activeTab + '"]').closest('li').addClass('active');
    }

    $("ul.nav-tabs a").click(function (e) {
        e.preventDefault();
        $(this).closest('li').siblings().removeClass('active');
        $(this).closest('li').addClass('active');
        $(this).tab('show');
        localStorage.setItem('categoryactiveTab', $(e.target).attr('href'));
    });
});
    </script>
{% endblock content %}
